//
//  ManyListenListTableViewCell.m
//  NewMusic
//
//  Created by dllo on 15/11/15.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "ManyListenListTableViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
@interface ManyListenListTableViewCell ()
//背景图
@property(nonatomic, retain) UIView *backView;
//排序
@property(nonatomic, retain) UILabel *queueLabel;
//名称
@property(nonatomic, retain) UILabel *nameLabel;
//歌手名
@property(nonatomic, retain) UILabel *singerNameLabel;
//心形图片
@property(nonatomic, retain) UIImageView *heartImage;
//喜欢人数
@property(nonatomic, retain) UILabel  *favoritiesLabel;
//下拉
@property(nonatomic, retain) UIButton *showButton;
@property(nonatomic, retain) UILabel *lineLabel;
@end
@implementation ManyListenListTableViewCell
- (void)dealloc {
    [_lineLabel release];
    [_backView release];
    [_queueLabel release];
    [_nameLabel release];
    [_singerNameLabel release];
    [_heartImage release];
    [_favoritiesLabel release];
    [_showButton release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 创建视图
        [self createSubView];
    }
    return  self;
}
#pragma mark 创建视图
- (void)createSubView {
    self.backView = [[UIView alloc]init];
    self.backView.backgroundColor = [UIColor whiteColor];
    self.backView.alpha = 0.05;
    [self.contentView addSubview:self.backView];
    [self.backView release];
    //排序
    self.queueLabel = [[UILabel alloc]init];
//        self.queueLabel.backgroundColor = [UIColor redColor];
    self.queueLabel.textAlignment = NSTextAlignmentCenter;
    self.queueLabel.font = [UIFont fontWithName:@"AmericanTypewriter" size:17];
    self.queueLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.queueLabel];
    [self.queueLabel release];
    
    //歌手名字
    self.singerNameLabel = [[UILabel alloc]init];
//        self.singerNameLabel.backgroundColor = [UIColor yellowColor];
    self.singerNameLabel.textColor = [UIColor colorWithWhite:0.843 alpha:1.000];
    self.singerNameLabel.font = [UIFont systemFontOfSize:15];
    
    [self.contentView addSubview:self.singerNameLabel];
    [self.singerNameLabel release];
    
    //歌名
    self.nameLabel = [[UILabel alloc]init];
//        self.nameLabel.backgroundColor = [UIColor purpleColor];
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.font = [UIFont systemFontOfSize:19];
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel release];
    
    //心形图片
    self.heartImage = [[UIImageView alloc]init];
//        self.heartImage.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.heartImage];
    [self.heartImage release];
    
    //喜欢人数
    self.favoritiesLabel = [[UILabel alloc]init];
//        self.favoritiesLabel.backgroundColor = [UIColor blueColor];
    self.favoritiesLabel.textColor = [UIColor colorWithWhite:0.827 alpha:1.000];
    self.favoritiesLabel.font = [UIFont fontWithName:@"AmericanTypewriter" size:15];
    [self.contentView addSubview:self.favoritiesLabel];
    [self.favoritiesLabel release];
    
    //下拉
    self.showButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.showButton.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.showButton];
    
    //线
    self.lineLabel = [[UILabel alloc]init];
    self.lineLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.lineLabel];
    [_lineLabel release];
}
#pragma mark  设置大小
- (void)layoutSubviews {
    [super layoutSubviews];
    //排行
//    self.queueLabel.frame = CGRectMake(10, 5, 40, self.frame.size.height - 10);
    //歌曲名字
    self.nameLabel.frame = CGRectMake( 10, 5, self.frame.size.width / 5 * 3, (self.frame.size.height - 10)/ 2);
//    self.backView.frame = CGRectMake(5, self.queueLabel.frame.origin.y, self.frame.size.width -10, self.frame.size.height - self.queueLabel.frame.origin.y * 2);
    //歌手名字
    if (19 * [_dataSongsModel.singerName lengthOfBytesUsingEncoding:NSUTF8StringEncoding] / 2 > self.frame.size.width / 2) {
        self.singerNameLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.size.height + self.nameLabel.frame.origin.y, self.frame.size.width / 2, self.nameLabel.frame.size.height);
    }else {
    self.singerNameLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.size.height + self.nameLabel.frame.origin.y, 19 * [_dataSongsModel.singerName lengthOfBytesUsingEncoding:NSUTF8StringEncoding] / 2, self.nameLabel.frame.size.height);
    }
    //心形图片
    self.heartImage.frame = CGRectMake(self.singerNameLabel.frame.origin.x + self.singerNameLabel.frame.size.width, self.singerNameLabel.frame.origin.y + (self.singerNameLabel.frame.size.height - 20) / 2,  20, 20);
    //喜欢人数
    self.favoritiesLabel.frame = CGRectMake(self.heartImage.frame.origin.x + self.heartImage.frame.size.width, self.heartImage.frame.origin.y, self.nameLabel.frame.size.width - self.singerNameLabel.frame.size.width - self.heartImage.frame.size.width + 30, self.heartImage.frame.size.height);
    //播放图片
    self.showButton.frame = CGRectMake(self.frame.size.width - self.frame.size.width / 10 - 20, (self.frame.size.height - self.frame.size.width / 10) / 2 , self.frame.size.width / 10, self.frame.size.width / 10);
    //线
    self.lineLabel.frame = CGRectMake(0, self.frame.size.height - 0.3, self.frame.size.width, 0.3);
}
#pragma mark  重写queueString的setter方法
-(void)setQueueString:(NSString *)queueString {
    if (_queueString != queueString) {
        [_queueString release];
        _queueString = [queueString retain];
    }
    //排行
    self.queueLabel.text = queueString;
}
#pragma mark 重写dataSongsModel的setter方法
-(void)setDataSongsModel:(ListenDataSongsModel *)dataSongsModel {
    if (_dataSongsModel != dataSongsModel) {
        [_dataSongsModel release];
        _dataSongsModel = [dataSongsModel retain];
    }
    //歌曲名字
    self.nameLabel.text = dataSongsModel.name;
    //歌手名字
    self.singerNameLabel.text = dataSongsModel.singerName;
    //心形图片
    self.heartImage.image = [UIImage imageNamed:@"icon_dianzan"];
    //喜欢人数
    if (dataSongsModel.favorites.length < 4) {
        self.favoritiesLabel.text = dataSongsModel.favorites;
    }else {
    CGFloat number = [[NSString stringWithFormat:@"%.1f万", [dataSongsModel.favorites floatValue] / 10000] floatValue];
    NSNumber *num = [NSNumber numberWithFloat:number];
    self.favoritiesLabel.text = [NSString stringWithFormat:@"%@万", num];
    }
    //播放图片
    [self.showButton setImage:[UIImage imageNamed:@"icon_jiarugedan"] forState:UIControlStateNormal];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
